package com.atguigui.leetcode;

/**
 * 1184.公交站间的距离
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by  wangjiaxin  on 2022/7/24 20:53
 */
public class P1184DistanceBetweenBusStops {
    public static void main(String[] args) {
        Solution solution = new P1184DistanceBetweenBusStops().new Solution();

        int[] a = {1, 2, 3, 4};

        solution.distanceBetweenBusStops(a, 0, 3);
        // TO TEST
    }

    class Solution {
        public int distanceBetweenBusStops(int[] distance, int start, int destination) {
            int ans1 = getAns(distance, start, destination);
            int ans2 = getAns(distance, destination, start);
            return Math.min(ans1, ans2);
        }

        public int getAns(int[] distance, int start, int end) {
            int ans = 0;
            while (start != end) {
                if (start >= distance.length) {
                    start = 0;
                }
                if (start == end) {
                    break;
                }
                ans += distance[start];
                start++;
            }
            return ans;
        }
    }
}
